package statistics;

import java.util.Random;


public class ErlangDistribution extends Distribution{

    protected double lambda;
    protected int n;
    
    public ErlangDistribution( int n, double lambda  , Random random ){
        this.n = n;
        this.lambda = lambda;
    }
            

    public double expectation() {
       return n/lambda;
    }


    public double variance() {
        return n/(lambda*lambda);
    }


    public double nextRandom() {
        double sum=0;
        Random rand = new Random(); 
        Distribution exp = new ExponentialDistribution(lambda, rand);
        for(int i=1; i<=n; i++){
            sum = sum + exp.nextRandom();
        }
        return sum;   
    }
    
    
}